let mongoose = require('mongoose');
const conn = mongoose.createConnection('mongodb://localhost:27017/db201808',{ useNewUrlParser: true });
let UserSchema = new mongoose.Schema({
    username:{type:String,required:true},
    password:String,
    age:Number,
    createAt:{type:Date,default:Date.now}
},{collection:'user'});
// 集合的名字是来自于模型的名字，模型名》小写》复数
let User = conn.model('User',UserSchema);
let users = [];
for(let i=1;i<=10;i++){
   users.push({username:'zhufeng'+i,age:i,password:i});
}
/**
User.create(users,function(err,docs){
  console.log(docs);
});
 */
// sort skip limit 
let pageNum = 2;
let pageSize=3;
//User.find({},null,{skip:3,limit:3,sort:{age:1}});
User.find().skip(3).limit(3).sort({age:1}).exec(function(err,docs){
   console.log(docs);
});
